//五险自动带出
//
jQuery(document).ready(function(){


    var sbjndfid = WfForm.convertFieldNameToId("sbjnd");    //社保缴纳地
	var gjjndfid = WfForm.convertFieldNameToId("gjjjnd");  //公积金缴纳地
	
	var hklxfid = WfForm.convertFieldNameToId("hklx");  //户口类型
	var rsfwhfid = WfForm.convertFieldNameToId("rsfwh"); //人事范围
		//社保基数
   var sbjsFielid= WfForm.convertFieldNameToId("sbjsh");
   //级别
   var jb = WfForm.convertFieldNameToId("jb","detail_1");
   //保险类型
   var bxlxfid = WfForm.convertFieldNameToId("bxlx","detail_1");
   //级别描述
   var jbmsField = WfForm.convertFieldNameToId("gjjjbms");


	//社保缴纳地变更
	WfForm.bindFieldChangeEvent(sbjndfid, function(){



	//明细表字段
	//var bxlxdmfid = WfForm.convertFieldNameToId("bxlxdm","detail_1");

	//alert(bxlxdmfid);



	//明细表变更绑定
	//WfForm.bindDetailFieldChangeEvent(bxlxdmfid,function(id,rowIndex,value){

	//alert(id);
	//alert(rowIndex);
	//alert(value);








		var sbjndValue = WfForm.getFieldValue(sbjndfid);    //社保缴纳地


		//var gjjjndValue = WfForm.getFieldValue(gjjndfid);   //公积金缴纳地

		var hklxValue = WfForm.getFieldValue(hklxfid);   //户口类型
		var rsfwhValue = WfForm.getFieldValue(rsfwhfid);   //人事范围
				var sbjsValue=WfForm.getFieldValue(sbjsFielid);
        			if(sbjsValue == ""&&sbjndValue!=null&&sbjndValue!=""){
                			alert("社保基数为空");
		WfForm.changeFieldValue(sbjndfid, {
                                        value: ""                       });
                			return false ;
                		}
		if(sbjndValue == "" &&sbjndValue!=null&&sbjndValue!=""){
			alert("社保缴纳地为空");
					WfForm.changeFieldValue(sbjndfid, {
                                                    value: ""                       });
			return false ;
		}
		
		
		if(hklxValue == "" &&sbjndValue!=null&&sbjndValue!=""){
			alert("户口类型为空");
					WfForm.changeFieldValue(sbjndfid, {
                                                    value: ""                       });
			return false ;
		}
		
		if(rsfwhValue == ""&&sbjndValue!=null&&sbjndValue!=""){
			alert("人事范围为空");
					WfForm.changeFieldValue(sbjndfid, {
                                                    value: ""                       });
			return false;
		}
		

		
		if(sbjndValue!=null){

			
			
			
			//明细表字段

			var bxlxdmfid = WfForm.convertFieldNameToId("bxlxdm","detail_1");
			var xyfid = WfForm.convertFieldNameToId("xy","detail_1");
			var zfid = WfForm.convertFieldNameToId("z","detail_1");

				//明细表社保基数
            var sbjsFieldDetail=WfForm.convertFieldNameToId("sbjs","detail_1");
			
			
			
			 //ajax传值并根据返回值给表单字段赋值
            jQuery.ajax({
                url: "/api/weavernorth/action/database/AutowxyjAction/getSBData",
                data: {
					"sbjnd":sbjndValue,
					"hklx":hklxValue,
					"rsfw":rsfwhValue
				},
                dataType: 'text',
                async:false,
                success: function (data) {

						if(data!=""&&data!=null){
							

							
							
							var ListData = eval(data);

							
							WfForm.delDetailRow("detail_1", "all");
							   WfForm.changeFieldValue(jbmsField, {
                                                              value:""
                                                          });



							
							for(var i=0;i<ListData.length;i++){
							  //兼容ie
                                                          var addObj = {};
                                                          addObj[bxlxfid] = {value:ListData[i].bxlx};
                                                          addObj[bxlxdmfid] = {value:ListData[i].bxlxdm};
                                                          addObj[xyfid] = {value:ListData[i].xy};
                                                          addObj[zfid] = {value:ListData[i].z};
                                                          addObj[jb] = {value:ListData[i].jb};
                                                          addObj[sbjsFieldDetail] = {value:sbjsValue};
                                                          WfForm.addDetailRow("detail_1",addObj)/**/
//								WfForm.addDetailRow("detail_1",
//								{[bxlxfid]:{value:ListData[i].bxlx},
//								[bxlxdmfid]:{value:ListData[i].bxlxdm},
//								[xyfid]:{value:ListData[i].xy},
//								[zfid]:{value:ListData[i].z},
//								[jb]:{value:ListData[i].jb},
//								[sbjsFieldDetail]:{value:sbjsValue}
//
//								})
							}
							

							
						}
					},
                error: function (data) {  //请求失败时被调用的函数
                    alert("加载失败，请联系管理员！");
                }
            })
		}
		
	});
	


   //当级别改变时
    WfForm.bindDetailFieldChangeEvent(jb,
    function(id, index, value) {
    var bxlxValue=WfForm.getFieldValue(bxlxfid+"_"+index);
    var msValue;
    if(bxlxValue==5){

      if(value==0){
      msValue="个人7% 单位7%";

      }else if(value==1){
       msValue="个人8% 单位8%";
       }else if(value==2){
      msValue="个人10% 单位10%";
      }else if(value==3){
      msValue="个人11% 单位11%";
      }else if(value==4){
      msValue="个人12% 单位12%";
      }
      else if(value==5){
       msValue="个人6% 单位6%";
       }else if(value==6){
      msValue="个人5% 单位5%";
      }
   WfForm.changeFieldValue(jbmsField, {
                                  value:msValue
                              });

    }



    })
})
	
	

